<?php
/**
 * Created by PhpStorm.
 * User: JieHuiLong
 * Date: 2016/11/7
 * Time: 14:05
 */
use App\Models\RoleUser;
use App\Models\Role;
use App\Models\AdminUser as User;
use App\Models\Wechat;
use App\Models\WechatGroup;


function getQueryStr(){
    $queryStr = preg_replace('/&optime=\w+/i', '', $_SERVER['QUERY_STRING']);
    return '?' . $queryStr;
}


//终端判断 return bool true:是 false：否
function isMobile()
{
    if (isset ($_SERVER['HTTP_X_WAP_PROFILE'])) {
        return true;
    }
    if (isset ($_SERVER['HTTP_VIA'])) {
        return stristr($_SERVER['HTTP_VIA'], "wap") ? true : false;
    }
    if (isset ($_SERVER['HTTP_USER_AGENT'])) {
        $clientkeywords = array('nokia',
            'sony',
            'ericsson',
            'mot',
            'samsung',
            'htc',
            'sgh',
            'lg',
            'sharp',
            'sie-',
            'philips',
            'panasonic',
            'alcatel',
            'lenovo',
            'iphone',
            'ipod',
            'blackberry',
            'meizu',
            'android',
            'netfront',
            'symbian',
            'ucweb',
            'windowsce',
            'palm',
            'operamini',
            'operamobi',
            'openwave',
            'nexusone',
            'cldc',
            'midp',
            'wap',
            'mobile'
        );
        if (preg_match("/(" . implode('|', $clientkeywords) . ")/i", strtolower($_SERVER['HTTP_USER_AGENT']))) {
            return true;
        }
    }
    if (isset ($_SERVER['HTTP_ACCEPT'])) {
        if ((strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') !== false) && (strpos($_SERVER['HTTP_ACCEPT'], 'text/html') === false || (strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') < strpos($_SERVER['HTTP_ACCEPT'], 'text/html')))) {
            return true;
        }
    }
    return false;
}
/*
*获取ip地址
*return string
*/
function GetIp(){
    $realip = '';  
    $unknown = 'unknown';  
    if (isset($_SERVER)){  
        if(isset($_SERVER['HTTP_X_FORWARDED_FOR']) && !empty($_SERVER['HTTP_X_FORWARDED_FOR']) && strcasecmp($_SERVER['HTTP_X_FORWARDED_FOR'], $unknown)){  
            $arr = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);  
            foreach($arr as $ip){  
                $ip = trim($ip);  
                if ($ip != 'unknown'){  
                    $realip = $ip;  
                    break;  
                }  
            }  
        }else if(isset($_SERVER['HTTP_CLIENT_IP']) && !empty($_SERVER['HTTP_CLIENT_IP']) && strcasecmp($_SERVER['HTTP_CLIENT_IP'], $unknown)){  
            $realip = $_SERVER['HTTP_CLIENT_IP'];  
        }else if(isset($_SERVER['REMOTE_ADDR']) && !empty($_SERVER['REMOTE_ADDR']) && strcasecmp($_SERVER['REMOTE_ADDR'], $unknown)){  
            $realip = $_SERVER['REMOTE_ADDR'];  
        }else{  
            $realip = $unknown;  
        }  
    }else{  
        if(getenv('HTTP_X_FORWARDED_FOR') && strcasecmp(getenv('HTTP_X_FORWARDED_FOR'), $unknown)){  
            $realip = getenv("HTTP_X_FORWARDED_FOR");  
        }else if(getenv('HTTP_CLIENT_IP') && strcasecmp(getenv('HTTP_CLIENT_IP'), $unknown)){  
            $realip = getenv("HTTP_CLIENT_IP");  
        }else if(getenv('REMOTE_ADDR') && strcasecmp(getenv('REMOTE_ADDR'), $unknown)){  
            $realip = getenv("REMOTE_ADDR");  
        }else{  
            $realip = $unknown;  
        }  
    }  
    $realip = preg_match("/[\d\.]{7,15}/", $realip, $matches) ? $matches[0] : $unknown;  
    return $realip;  
} 
//获取点击事件
function getTouch($originate){
	if(preg_match('/(m.sogou.com\/bill_cpc)/i', strtolower($originate))){
		return "m.sogou.com/bill_cpc";
	}elseif(preg_match('/(m.sogou.com\/web\/searchList.jsp)/i', strtolower($originate))){
		return "m.sogou.com/web/searchList.jsp";
	}elseif(preg_match('/(a.mobi.sogou.com\/ad)/i', strtolower($originate))){
		return "a.mobi.sogou.com/ad";
	}elseif(preg_match('/(zhishi.sogou.com\/zhishi)/i', strtolower($originate))){
		return "zhishi.sogou.com/zhishi";
	}elseif(preg_match('/(wap.sogou.com\/web\/sl)/i', strtolower($originate))){
		return "wap.sogou.com/web/sl";
	}elseif(preg_match('/(wap.sogou.com\/waprdt)/i', strtolower($originate))){
		return "wap.sogou.com/waprdt";
	}elseif(preg_match('/(wisd.sogou.com\/bill_cpc)/i', strtolower($originate))){
		return "wisd.sogou.com/bill_cpc";
	}elseif(preg_match('/(wap.sogou.com\/bill_cpc)/i', strtolower($originate))){
		return "wap.sogou.com/bill_cpc";
	}elseif(preg_match('/(wenwen.sogou.com\/ms\/search.jsp)/i', strtolower($originate))){
		return "wenwen.sogou.com/ms/search.jsp";
	}elseif(preg_match('/(www.sogou.com\/bill_un)/i', strtolower($originate))){
		return "www.sogou.com/bill_un";
	}elseif(preg_match('/(ad.shengzx07.com\/622)/i', strtolower($originate))){
		return "ad.shengzx07.com/622";
	}else{
		return "unknown";
	}
}

//获取渠道
function returnAccout($domain){
	
    switch ($domain) {
        case 'ljfda.moonangel.net.cn':
            $accout = 'sg-ruxian';
            break;      
        case 'ljfh.9939vip.com':
            $accout = 'sg-sq81';
            break;            
        case 'ljfa.eababei.cn':
            $accout = 'sg-ks76';
            break;
        case 'ljf.eababen.cn':
            $accout = 'sg-mb64';
            break;
        case 'ljf.eabanve.cn':
            $accout = 'sg-fx29';
            break;
        case 'ljfd.eabenen.cn':
            $accout = 'sg-e20';
            break;
        case 'ljfa.eabenin.cn':
            $accout = 'sg-e19';
            break;
        case 'ljfa.jkgphjt.com':
            $accout = 'sg-mo12';
            break;
        case 'ljfc.eababeb.cn':
            $accout = 'sg-m9';
            break;
        case 'ljf.eababei.cn':
            $accout = 'sg-k4';
            break;
        case 'ljfe.eabanve.cn':
            $accout = 'sg-b46';
            break;
        case 'ljfh.eabenvn.cn':
            $accout = 'sg-b17';
            break;
        case 'ljhi.eababds.cn':
            $accout = 'sg-rf9';
            break;
        case 'ljfa.eabanin.cn':
            $accout = 'sg-jf140';
            break;
        case 'ljfb.eababdx.cn':
            $accout = 'sg-jf73';
            break;
        case 'ljfe.eabanang.cn':
            $accout = 'sg-jf137';
            break;
        case 'ljff.eabinao.cn':
            $accout = 'sg-a2';
            break;
        case 'ljfg.eabeno.cn':
            $accout = 'sg-d34';
            break;
        case 'ljfb.eckeji04.cn':
            $accout = 'sg-787666641146';
            break;
        case 'ljfd.etcom128.cn':
            $accout = 'sg-787666641199';
            break;
        case 'ljfe.etcom071.cn':
            $accout = 'sg-787666641287';
            break;
        case 'ljff.etcom093.cn':
            $accout = 'sg-787666641288';
            break;
        case 'ljfg.etcom143.cn':
            $accout = 'sg-787666641290';
            break;
        case 'ljfh.etcom110.cn':
            $accout = 'sg-787666641291';
            break;
        case 'ljfi.etcom118.cn':
            $accout = 'sg-787666641292';
            break;
        case 'ljfj.etcom120.cn':
            $accout = 'sg-787666641293';
            break;
        case 'ljfk.etcom144.cn':
            $accout = 'sg-787666641294';
            break;
        case 'ljfl.etcom116.cn':
            $accout = 'sg-787666641297';
            break;
        case 'ljfm.etcom125.cn':
            $accout = 'sg-787666641328';
            break;
        case 'ljfn.etcom120.cn':
            $accout = 'sg-787666641344';
            break;
        case 'ljfo.etcom144.cn':
            $accout = 'sg-787666641345';
            break;
        case 'ljfp.etcom102.cn':
            $accout = 'sg-787666641346';
            break;
        case 'ljfq.etcom103.cn':
            $accout = 'sg-787666641347';
            break;
        case 'ljf.yzcfkj.org.cn':
            $accout = 'sg-yzfc134';
            break;
        case 'ljqb13.eababdx.cn':
            $accout = 'sg-qb13';
            break;    
        case 'sljqb13.eababdx.cn':
            $accout = 'sg-qb13';
            break;   
        case 'ljf1.lcudgxm.com':
            $accout = 'sg-when1';
            break;    
        case 'ljf5.lcudgxm.com':
            $accout = 'sg-when5';
            break;                                    
        case 'ljf.rkvrlkm.com':
            $accout = 'bd-壹健康111';
            break;
        case 'jla.rkvrlkm.com':
            $accout = 'bd-壹健康111';
            break;
        case 'ljf.whahd.com':
            $accout = 'bd-可旺04';
            break;
        case 'ljf.odybx9z.com':
            $accout = 'bd-贝信26';
            break;  
        case 'ljfa.odybx9z.com':
            $accout = 'bd-贝信31';
            break;  
        case 'bdljf.yiuydsgf.top':
            $accout = 'bd-sz-化mtsy';
            break;                      
        case 'jla.bhajiofh.top':
            $accout = 'bd-cq-化ja';
            break;
        case 'bdjla.lvtop9.com':
            $accout = 'bd-绿瘦健康9-S';
            break;
        case 'bdfjla.lvtop9.com':
            $accout = 'bd-绿瘦健康9-F';
            break;
        case 'ljf.kt89.top':
            $accout = '360-sopz264862';
            break;
        case 'jhp.myjydedu.cn':
            $accout = 'UC-ydd-wai4';
            break;
        case 'ljf.jfggsb.cn':
            $accout = 'UC-i乐乐呢40';
            break;
        case 'ljfa.cqamdzj.cn':
            $accout = 'UC-一个和尚t6';
            break;
        case 'ljfb.cqamdzj.cn':
            $accout = 'UC-一个和尚t7';
            break;
        case 'ljf.cqamdzj.cn':
            $accout = 'UC-一个和尚t9';
            break;
        case 'ljfc.cqamdzj.cn':
            $accout = 'UC-一个和尚t10';
            break;
        case 'jhh1.cqamdzj.cn':
            $accout = 'UC-和尚化缘t1';
            break;
        case 'jhh2.cqamdzj.cn':
            $accout = 'UC-和尚化缘t2';
            break;
        case 'jhh3.cqamdzj.cn':
            $accout = 'UC-和尚化缘t3';
            break;
        case 'jhh4.cqamdzj.cn':
            $accout = 'UC-和尚化缘t4';
            break;
        case 'jhh5.cqamdzj.cn':
            $accout = 'UC-和尚化缘t5';
            break;
        case 'jhh6.cqamdzj.cn':
            $accout = 'UC-和尚化缘t6';
            break;
        case 'smzr01.zrasf.cn':
            $accout = 'UC-五谷不分1';
            break;
        case 'smzr02.zrasf.cn':
            $accout = 'UC-五谷不分2';
            break;
        default:
            $accout = $domain;
            break;
    }
    
	return $accout;
}

//获取渠道
function getChannel($originate){
	if(preg_match('/(sogou.com)/i', strtolower($originate))){
		return "sogou.com";
	}elseif(preg_match('/(shengzx07.com)/i', strtolower($originate))){
		return "shengzx07.com";
	}else{
		return "unknown";
	}
}
//获取关键词
function getKeyword($originate){
	$arr1 = explode("keyword=",$originate);
	if(!isset($arr1[1])){
		return "";
	}else{
		$arr2 = explode('&',$arr1[1]);
		return $arr2[0];
	}
}

//判断系统
function check_system($user_agent){
	if(preg_match('/(symbian)/i', strtolower($user_agent))){
		return "symbian";
	}elseif(preg_match('/(android)/i', strtolower($user_agent))){
		return "android";
	}elseif(preg_match('/(iphone)/i', strtolower($user_agent))){
		return "iphone";
	}elseif(preg_match('/(Macintosh)/i', strtolower($user_agent))){
		return "mac";
	}elseif(preg_match('/(Windows)/i', strtolower($user_agent))){
		return "Windows";
	}elseif(preg_match('/(iPad)/i', strtolower($user_agent))){
		return "iPad";
	}else{
		return "unknown";
	}
}
//判断浏览器
function check_browser($user_agent){
	if(preg_match('/(MQQBrowser)/i', strtolower($user_agent))){
		return "QQ浏览器";
	}elseif(preg_match('/(MiuiBrowser)/i', strtolower($user_agent))){
		return "小米浏览器";
	}elseif(preg_match('/(VivoBrowser)/i', strtolower($user_agent))){
		return "vivo浏览器";
	}elseif(preg_match('/(OppoBrowser)/i', strtolower($user_agent))){
		return "Oppo浏览器";
	}elseif(preg_match('/(UCBrowser)/i', strtolower($user_agent))){
		return "UC浏览器";
	}elseif(preg_match('/(KuaiMaBrowser)/i', strtolower($user_agent))){
		return "快马浏览器";
	}elseif(preg_match('/(MicroMessenger)/i', strtolower($user_agent))){
		return "微信浏览器";
	}elseif(preg_match('/(ipad|iphone)/i', strtolower($user_agent))){
		return "苹果浏览器";
	}else{
		return "其他";
	}
}
//根据ip获取省份、城市
function GetIpLookup($ip = ''){ 
    if(!is_ip($ip)){  
        return ['status'=>510,'msg'=>'请输入正确的ip地址','province'=>'','city'=>'']; 
    }  
    $res = @file_get_contents('http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js&ip='.$ip);  
    if(empty($res)){ return false; }  
    $jsonMatches = array();  
    preg_match('#\{.+?\}#', $res, $jsonMatches);  
    if(!isset($jsonMatches[0])){ return false; }  
    $json = json_decode($jsonMatches[0], true);  
    if(isset($json['ret']) && $json['ret'] == 1){  
        $json['ip'] = $ip;  
        unset($json['ret']);  
    }else{  
        return false;  
    }  
    return $json;  
}
function is_ip($gonten){  
	$ip = explode(".",$gonten);  
	for($i=0;$i<count($ip);$i++)  
	{
		if($ip[$i]>255){  
			return (0);  
		}
	}
	return preg_match("/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/",$gonten);  
}
//判断设备
function check_device($user_agent){
	/* if(preg_match('/(m2 note)/i', strtolower($user_agent))){
		return "魅蓝NOTE2";
	}elseif(preg_match('/(PLK-TL01H)/i', strtolower($user_agent))){
		return "荣耀7";
	}elseif(preg_match('/(MP1512)/i', strtolower($user_agent))){
		return "美图MP1512";
	}elseif(preg_match('/(OPPO A53)/i', strtolower($user_agent))){
		return "OPPO A53";
	}elseif(preg_match('/(vivo Y67)/i', strtolower($user_agent))){
		return "vivo Y67";
	}elseif(preg_match('/(vivo Y55L)/i', strtolower($user_agent))){
		return "vivo Y55L";
	}elseif(preg_match('/(vivo X7Plus)/i', strtolower($user_agent))){
		return "vivo X7 Plus";
	}elseif(preg_match('/(vivo X7)/i', strtolower($user_agent))){
		return "vivo X7";
	}elseif(preg_match('/(BBG-vivo X3V)/i', strtolower($user_agent))){
		return "步步高 BBG-vivo X3V";
	}elseif(preg_match('/(iPhone OS 9)/i', strtolower($user_agent))){
		return "iPhone 9";
	}elseif(preg_match('/(vivo X9)/i', strtolower($user_agent))){
		return "vivo X9";
	}elseif(preg_match('/(GT-I9158)/i', strtolower($user_agent))){
		return "三星 GT-I9158";
	}elseif(preg_match('/(vivo Y27)/i', strtolower($user_agent))){
		return "vivo Y27";
	}elseif(preg_match('/(MI 5)/i', strtolower($user_agent))){
		return "小米 5";
	}elseif(preg_match('/(SM-G9250)/i', strtolower($user_agent))){
		return "三星 SM-G9250";
	}elseif(preg_match('/(OPPO R9s)/i', strtolower($user_agent))){
		return "OPPO R9s";
	}elseif(preg_match('/(FRD-AL10)/i', strtolower($user_agent))){
		return "荣耀 8";
	}elseif(preg_match('/(Redmi Pro)/i', strtolower($user_agent))){
		return "红米 pro";
	}elseif(preg_match('/(PRA-AL00X|PRA-AL00)/i', strtolower($user_agent))){
		return "荣耀8青春版";
	}elseif(preg_match('/(KNT-AL10)/i', strtolower($user_agent))){
		return "荣耀v8";
	}elseif(preg_match('/(vivo X6S)/i', strtolower($user_agent))){
		return "vivo X6S";
	}elseif(preg_match('/(vivo X3L)/i', strtolower($user_agent))){
		return "vivo X3L";
	}elseif(preg_match('/(HUAWEI RIO-TL00)/i', strtolower($user_agent))){
		return "华为G7 Plus";
	}elseif(preg_match('/(vivo X7L)/i', strtolower($user_agent))){
		return "vivo X7L";
	}elseif(preg_match('/(R7Plus)/i', strtolower($user_agent))){
		return "OPPO R7 Plus";
	}elseif(preg_match('/(OPPO R7s)/i', strtolower($user_agent))){
		return "OPPO R7s";
	}elseif(preg_match('/(OPPO R9)/i', strtolower($user_agent))){
		return "OPPO R9";
	}elseif(preg_match('/(vivo Y31)/i', strtolower($user_agent))){
		return "vivo Y31";
	}elseif(preg_match('/(HTC M8St)/i', strtolower($user_agent))){
		return "HTC ONE E8";
	}elseif(preg_match('/(FRD-AL00)/i', strtolower($user_agent))){
		return "荣耀8";
	}elseif(preg_match('/(BLN-AL10)/i', strtolower($user_agent))){
		return "荣耀6X";
	}elseif(preg_match('/(BLN-AL20)/i', strtolower($user_agent))){
		return "荣耀6X 高配版";
	}elseif(preg_match('/(Lenovo K30-T)/i', strtolower($user_agent))){
		return "联想 K30-T";
	}elseif(preg_match('/(vivo X9i)/i', strtolower($user_agent))){
		return "vivo X9i";
	}elseif(preg_match('/(vivo Y31A)/i', strtolower($user_agent))){
		return "vivo Y31A";
	}elseif(preg_match('/(KNT-AL20)/i', strtolower($user_agent))){
		return "荣耀V8 高配版";
	}elseif(preg_match('/(PLK-AL10)/i', strtolower($user_agent))){
		return "荣耀7";
	}elseif(preg_match('/(CAM-UL00)/i', strtolower($user_agent))){
		return "荣耀畅玩5A";
	}elseif(preg_match('/(SUGAR S9)/i', strtolower($user_agent))){
		return "SUGAR S9";
	}elseif(preg_match('/(SUGAR F9)/i', strtolower($user_agent))){
		return "SUGAR F9";
	}elseif(preg_match('/(SUGAR 2C)/i', strtolower($user_agent))){
		return "SUGAR 2C";
	}elseif(preg_match('/(SUGAR Y7)/i', strtolower($user_agent))){
		return "SUGAR Y7";
	}elseif(preg_match('/(M5 Note)/i', strtolower($user_agent))){
		return "魅蓝NOTE5";
	}elseif(preg_match('/(KIW-AL10|KIW-UL00)/i', strtolower($user_agent))){
		return "荣耀畅玩5X";
	}elseif(preg_match('/(CHE-TL00H|HonorChe2-UL00|Che2-TL00M)/i', strtolower($user_agent))){
		return "荣耀畅玩4X";
	}elseif(preg_match('/(OPPO A59m)/i', strtolower($user_agent))){
		return "OPPO A59m";
	}elseif(preg_match('/(Redmi 4)/i', strtolower($user_agent))){
		return "红米 4";
	}elseif(preg_match('/(OPPO A59s)/i', strtolower($user_agent))){
		return "OPPO A59s";
	}elseif(preg_match('/(vivo X6D)/i', strtolower($user_agent))){
		return "vivo X6D";
	}elseif(preg_match('/(PLK-TL01H)/i', strtolower($user_agent))){
		return "荣耀7";
	}elseif(preg_match('/(HUAWEI VNS-DL00|HUAWEI VNS-AL00)/i', strtolower($user_agent))){
		return "华为G9青春版";
	}elseif(preg_match('/(OB-OPPO A31c)/i', strtolower($user_agent))){
		return "OPPO A31c";
	}elseif(preg_match('/(OPPO A57)/i', strtolower($user_agent))){
		return "OPPO A57";
	}elseif(preg_match('/(vivo V3M)/i', strtolower($user_agent))){
		return "vivo V3M";
	}elseif(preg_match('/(vivo Y51A)/i', strtolower($user_agent))){
		return "vivo Y51A";
	}elseif(preg_match('/(vivo X5S)/i', strtolower($user_agent))){
		return "vivo X5S";
	}elseif(preg_match('/(Le X621)/i', strtolower($user_agent))){
		return "乐视 X621";
	}elseif(preg_match('/(Le X620)/i', strtolower($user_agent))){
		return "乐视 X620";
	}elseif(preg_match('/(KIW-TL00)/i', strtolower($user_agent))){
		return "荣耀畅玩5X";
	}elseif(preg_match('/(HM NOTE)/i', strtolower($user_agent))){
		return "红米 note";
	}elseif(preg_match('/(OPPO A37m)/i', strtolower($user_agent))){
		return "OPPO A37m";
	}elseif(preg_match('/(vivo X9Plus)/i', strtolower($user_agent))){
		return "vivo X9 Plus";
	}elseif(preg_match('/(PE-TL20)/i', strtolower($user_agent))){
		return "荣耀6 Plus";
	}elseif(preg_match('/(LA-S33)/i', strtolower($user_agent))){
		return "小辣椒 S33";
	}elseif(preg_match('/(KOT49H|2014011)/i', strtolower($user_agent))){
		return "红米1s";
	}elseif(preg_match('/(Redmi Note 2)/i', strtolower($user_agent))){
		return "红米 note2";
	}elseif(preg_match('/(ASUS_X008)/i', strtolower($user_agent))){
		return "华硕飞马3";
	}elseif(preg_match('/(vivo X5Pro)/i', strtolower($user_agent))){
		return "vivo X5Pro";
	}elseif(preg_match('/(vivo Y55A)/i', strtolower($user_agent))){
		return "vivo Y55A";
	}elseif(preg_match('/(vivo Y22L)/i', strtolower($user_agent))){
		return "vivo Y22L";
	}elseif(preg_match('/(MZ-m3)/i', strtolower($user_agent))){
		return "魅族3";
	}elseif(preg_match('/(vivo Y51)/i', strtolower($user_agent))){
		return "vivo Y51";
	}elseif(preg_match('/(M1 E)/i', strtolower($user_agent))){
		return "魅蓝E";
	}elseif(preg_match('/(HONORBLN-AL10|BLN-AL40)/i', strtolower($user_agent))){
		return "荣耀畅玩6X";
	}elseif(preg_match('/(VTR-AL00)/i', strtolower($user_agent))){
		return "华为P10";
	}elseif(preg_match('/(Redmi 3S)/i', strtolower($user_agent))){
		return "红米3s";
	}elseif(preg_match('/(Redmi 2|2014813)/i', strtolower($user_agent))){
		return "红米2";
	}elseif(preg_match('/(Redmi 2A|HM 2A)/i', strtolower($user_agent))){
		return "红米2A";
	}elseif(preg_match('/(Redmi 3x)/i', strtolower($user_agent))){
		return "红米3x";
	}elseif(preg_match('/(Redmi 3)/i', strtolower($user_agent))){
		return "红米3";
	}elseif(preg_match('/(Redmi 4x)/i', strtolower($user_agent))){
		return "红米4x";
	}elseif(preg_match('/(Redmi note 3)/i', strtolower($user_agent))){
		return "红米 note3";
	}elseif(preg_match('/(Redmi note 4x)/i', strtolower($user_agent))){
		return "红米 note4x";
	}elseif(preg_match('/(MI 6)/i', strtolower($user_agent))){
		return "小米 6";
	}elseif(preg_match('/(MI 4)/i', strtolower($user_agent))){
		return "小米 4";
	}elseif(preg_match('/(Mi-4c)/i', strtolower($user_agent))){
		return "小米 4c";
	}elseif(preg_match('/(MI MAX)/i', strtolower($user_agent))){
		return "小米 max";
	}elseif(preg_match('/(MI max 2)/i', strtolower($user_agent))){
		return "小米 max 2";
	}elseif(preg_match('/(MI note 2)/i', strtolower($user_agent))){
		return "小米 note2";
	}elseif(preg_match('/(MI mix)/i', strtolower($user_agent))){
		return "小米 mix";
	}elseif(preg_match('/(MI 5s)/i', strtolower($user_agent))){
		return "小米 5s";
	}elseif(preg_match('/(MI 5c)/i', strtolower($user_agent))){
		return "小米 5c";
	}elseif(preg_match('/(vivo Xplay3S)/i', strtolower($user_agent))){
		return "vivo Xplay3S";
	}elseif(preg_match('/(KTU84P)/i', strtolower($user_agent))){
		return "小米 3";
	}elseif(preg_match('/(MI 2S)/i', strtolower($user_agent))){
		return "小米 2s";
	}elseif(preg_match('/(TAG-AL00|HUAWEI TAG-TL00)/i', strtolower($user_agent))){
		return "荣耀畅享5s";
	}elseif(preg_match('/(MZ-m1)/i', strtolower($user_agent))){
		return "魅族 m1";
	}elseif(preg_match('/(AoleDior)/i', strtolower($user_agent))){
		return "奥乐迪奥";
	}elseif(preg_match('/(vivo Xplay5A)/i', strtolower($user_agent))){
		return "vivo Xplay5A";
	}elseif(preg_match('/(DOOV L5M)/i', strtolower($user_agent))){
		return "朵唯 L5m";
	}elseif(preg_match('/(vivo Y23L)/i', strtolower($user_agent))){
		return "vivo Y23L";
	}elseif(preg_match('/(lephone W2)/i', strtolower($user_agent))){
		return "乐丰 W2";
	}elseif(preg_match('/(1501-M02)/i', strtolower($user_agent))){
		return "奇酷 1501-M02";
	}elseif(preg_match('/(vivo Y37)/i', strtolower($user_agent))){
		return "vivo Y37";
	}elseif(preg_match('/(vivo Y66L)/i', strtolower($user_agent))){
		return "vivo Y66L";
	}elseif(preg_match('/(vivo Y55)/i', strtolower($user_agent))){
		return "vivo Y55";
	}elseif(preg_match('/(FRD-DL00)/i', strtolower($user_agent))){
		return "荣耀8";
	}elseif(preg_match('/(vivo Y66)/i', strtolower($user_agent))){
		return "vivo Y66";
	}elseif(preg_match('/(vivo Y35)/i', strtolower($user_agent))){
		return "vivo Y35";
	}elseif(preg_match('/(OPPO R7)/i', strtolower($user_agent))){
		return "OPPO R7";
	}elseif(preg_match('/(ZTE BA610C)/i', strtolower($user_agent))){
		return "中兴远航4";
	}elseif(preg_match('/(ATH-AL00)/i', strtolower($user_agent))){
		return "华为7i";
	}elseif(preg_match('/(HUAWEI NXT-AL10|HUAWEI NXT-DL00|HUAWEI NXT-TL00)/i', strtolower($user_agent))){
		return "华为mate8";
	}elseif(preg_match('/(Moto X Pro)/i', strtolower($user_agent))){
		return "摩托罗拉 X pro";
	}elseif(preg_match('/(R827T)/i', strtolower($user_agent))){
		return "OPPO R827T";
	}elseif(preg_match('/(HUAWEI MLA-AL10)/i', strtolower($user_agent))){
		return "华为麦芒5 高配版";
	}elseif(preg_match('/(HUAWEIMHA-AL00)/i', strtolower($user_agent))){
		return "华为mate9";
	}elseif(preg_match('/(CAM-AL00)/i', strtolower($user_agent))){
		return "荣耀畅玩5A";
	}elseif(preg_match('/(DUK-AL20)/i', strtolower($user_agent))){
		return "荣耀v9";
	}elseif(preg_match('/(HUAWEI Y330-C00)/i', strtolower($user_agent))){
		return "华为Y33-C00";
	}elseif(preg_match('/(Le X520)/i', strtolower($user_agent))){
		return "乐视 X520";
	}elseif(preg_match('/(SM-G9350)/i', strtolower($user_agent))){
		return "三星 G9350";
	}elseif(preg_match('/(SM-G3502I)/i', strtolower($user_agent))){
		return "三星 G3502I";
	}elseif(preg_match('/(SCL-TL00H|CHM-TL00H|CHM-TL00H)/i', strtolower($user_agent))){
		return "荣耀畅玩4C";
	}elseif(preg_match('/(SM-J5008)/i', strtolower($user_agent))){
		return "三星 J5008";
	}elseif(preg_match('/(SM-N9009 )/i', strtolower($user_agent))){
		return "三星 N9009";
	}elseif(preg_match('/(1603-A03)/i', strtolower($user_agent))){
		return "360 N4A";
	}elseif(preg_match('/(SM-G9280)/i', strtolower($user_agent))){
		return "三星 G9280";
	}elseif(preg_match('/(lephone T7+)/i', strtolower($user_agent))){
		return "乐丰 T7+";
	}elseif(preg_match('/(SM-A5108)/i', strtolower($user_agent))){
		return "三星 A5108";
	}elseif(preg_match('/(R819T)/i', strtolower($user_agent))){
		return "OPPO R819T";
	}elseif(preg_match('/(vivo_Y613F)/i', strtolower($user_agent))){
		return "vivo Y613F";
	}elseif(preg_match('/(SCL-TL00H|SCL-AL00|SCL-TL00|HW-SCL-CL00)/i', strtolower($user_agent))){
		return "荣耀4A";
	}elseif(preg_match('/(NEM-UL10|NEM-AL10)/i', strtolower($user_agent))){
		return "荣耀畅玩5C";
	}elseif(preg_match('/(ONEPLUS A3000)/i', strtolower($user_agent))){
		return "一加 3";
	}elseif(preg_match('/(HUAWEI TIT-CL10|HUAWEI TIT-TL00)/i', strtolower($user_agent))){
		return "华为畅享5";
	}elseif(preg_match('/(GT-N7100)/i', strtolower($user_agent))){
		return "三星 GALAXY Note II";
	}elseif(preg_match('/(GN9010)/i', strtolower($user_agent))){
		return "金立 S6";
	}elseif(preg_match('/(HUAWEI GRA-CL00|HUAWEI GRA-UL10|HUAWEI GRA-CL10|HUAWEI GRA-TL00|HUAWEI GRA-CL00)/i', strtolower($user_agent))){
		return "华为 P8";
	}elseif(preg_match('/(H60-L01)/i', strtolower($user_agent))){
		return "荣耀6";
	}elseif(preg_match('/(HUAWEI CAZ-AL10)/i', strtolower($user_agent))){
		return "华为nova";
	}elseif(preg_match('/(HUAWEI CUN-TL00|HUAWEI CUN-TL00|HUAWEI CUN-AL00)/i', strtolower($user_agent))){
		return "华为畅玩5";
	}elseif(preg_match('/(GIONEE-GN8003)/i', strtolower($user_agent))){
		return "金立 M6";
	}elseif(preg_match('/(vivo Y53)/i', strtolower($user_agent))){
		return "vivo Y53";
	}elseif(preg_match('/(F100)/i', strtolower($user_agent))){
		return "金立 F100";
	}elseif(preg_match('/(N5117|N5117)/i', strtolower($user_agent))){
		return "OPPO N1 Mini";
	}elseif(preg_match('/(vivo X6L)/i', strtolower($user_agent))){
		return "vivo X6L";
	}elseif(preg_match('/(Coolpad Y803-9)/i', strtolower($user_agent))){
		return "酷派 Y803-9";
	}elseif(preg_match('/(R8007)/i', strtolower($user_agent))){
		return "OPPO R1s";
	}elseif(preg_match('/(vivo X6A)/i', strtolower($user_agent))){
		return "vivo X6A";
	}elseif(preg_match('/(vivo V3)/i', strtolower($user_agent))){
		return "vivo V3";
	}elseif(preg_match('/(GN5001)/i', strtolower($user_agent))){
		return "金立金钢";
	}elseif(preg_match('/(1501_M02)/i', strtolower($user_agent))){
		return "360 F4";
	}elseif(preg_match('/(GN152)/i', strtolower($user_agent))){
		return "金立 GN152";
	}elseif(preg_match('/(A680Q)/i', strtolower($user_agent))){
		return "魅蓝E";
	}elseif(preg_match('/(GN9012)/i', strtolower($user_agent))){
		return "金立S6 Pro";
	}elseif(preg_match('/(ZTE BA910)/i', strtolower($user_agent))){
		return "中兴Blade BA910";
	}elseif(preg_match('/(M631)/i', strtolower($user_agent))){
		return "中国移动A1s";
	}elseif(preg_match('/(Letv X500)/i', strtolower($user_agent))){
		return "乐视乐1S";
	}elseif(preg_match('/(SM-G9287)/i', strtolower($user_agent))){
		return "三星 G9287";
	}elseif(preg_match('/(HUAWEIEDISON-AL10)/i', strtolower($user_agent))){
		return "华为note8";
	}elseif(preg_match('/(BLN-AL40)/i', strtolower($user_agent))){
		return "荣耀畅玩6X";
	}elseif(preg_match('/(HUAWEI G525-U00)/i', strtolower($user_agent))){
		return "华为G525";
	}elseif(preg_match('/(koobee S106M)/i', strtolower($user_agent))){
		return "酷比 S106m";
	}elseif(preg_match('/(R6007)/i', strtolower($user_agent))){
		return "OPPO R6007";
	}elseif(preg_match('/(F105)/i', strtolower($user_agent))){
		return "金立 F105";
	}elseif(preg_match('/(HUAWEI MT7-TL00|HUAWEI_MT7-TL10_TD)/i', strtolower($user_agent))){
		return "华为mate7";
	}elseif(preg_match('/(GiONEE-V183)/i', strtolower($user_agent))){
		return "金立 V183";
	}elseif(preg_match('/(GiONEE-F301)/i', strtolower($user_agent))){
		return "金立 F301";
	}elseif(preg_match('/(OPPO A33m|OPPO A33t|OPPO A33)/i', strtolower($user_agent))){
		return "OPPO A33";
	}elseif(preg_match('/(X9007)/i', strtolower($user_agent))){
		return "OPPO Find 7";
	}elseif(preg_match('/(VIV-vivo Y937)/i', strtolower($user_agent))){
		return "vivo Y937";
	}elseif(preg_match('/(vivo X510t)/i', strtolower($user_agent))){
		return "vivo Xplay";
	}elseif(preg_match('/(VIV-vivo Y913)/i', strtolower($user_agent))){
		return "vivo Y913";
	}elseif(preg_match('/(X800+)/i', strtolower($user_agent))){
		return "乐视 乐1pro";
	}elseif(preg_match('/(SM-N7508V)/i', strtolower($user_agent))){
		return "三星GALAXY Note 3 Lite";
	}elseif(preg_match('/(VIE-AL10)/i', strtolower($user_agent))){
		return "华为P9 Plus";
	}elseif(preg_match('/(NCE-AL10)/i', strtolower($user_agent))){
		return "华为 NCE-AL10";
	}elseif(preg_match('/(DUK-TL30)/i', strtolower($user_agent))){
		return "荣耀V9";
	}elseif(preg_match('/(G620S-UL00)/i', strtolower($user_agent))){
		return "荣耀畅玩4";
	}elseif(preg_match('/(K-Touch Tou ch 2c)/i', strtolower($user_agent))){
		return "天语（K-Touch）touch2c";
	}elseif(preg_match('/(X600)/i', strtolower($user_agent))){
		return "乐视乐1";
	}elseif(preg_match('/(PLK-UL00)/i', strtolower($user_agent))){
		return "荣耀7";
	}elseif(preg_match('/(SM-P550)/i', strtolower($user_agent))){
		return "Galaxy Tab A with S Pen 9.7";
	}elseif(preg_match('/(vivo X6Plus)/i', strtolower($user_agent))){
		return "vivo X6 Plus";
	}elseif(preg_match('/(HTC D816t)/i', strtolower($user_agent))){
		return "HTC Desire 816";
	}elseif(preg_match('/(HuaweiMediaPad)/i', strtolower($user_agent))){
		return "华为MediaPad";
	}elseif(preg_match('/(Lenovo K50-t3s)/i', strtolower($user_agent))){
		return "联想乐檬K3 Note";
	}elseif(preg_match('/(Coolpad 9190L)/i', strtolower($user_agent))){
		return "酷派S6";
	}elseif(preg_match('/(vivo Y17T)/i', strtolower($user_agent))){
		return "vivo Y17T";
	}elseif(preg_match('/(m1 metal)/i', strtolower($user_agent))){
		return "魅蓝metal";
	}elseif(preg_match('/(SM-N7509V)/i', strtolower($user_agent))){
		return "三星N7509V";
	}elseif(preg_match('/(C106)/i', strtolower($user_agent))){
		return "酷派 cool1";
	}elseif(preg_match('/(GIONEE-F103)/i', strtolower($user_agent))){
		return "金立 F103";
	}elseif(preg_match('/(vivo Y33)/i', strtolower($user_agent))){
		return "vivo Y33";
	}elseif(preg_match('/(SM-G9008V)/i', strtolower($user_agent))){
		return "三星GALAXY S5";
	}elseif(preg_match('/(SM-C9000)/i', strtolower($user_agent))){
		return "三星GALAXY C9 Pro";
	}elseif(preg_match('/(MI NOTE)/i', strtolower($user_agent))){
		return "小米 note";
	}elseif(preg_match('/(HUAWEI RIO-AL00)/i', strtolower($user_agent))){
		return "华为麦芒4";
	}elseif(preg_match('/(M3s)/i', strtolower($user_agent))){
		return "魅蓝3s";
	}elseif(preg_match('/(ZUK Z2131)/i', strtolower($user_agent))){
		return "联想ZUK Z2";
	}elseif(preg_match('/(A0001)/i', strtolower($user_agent))){
		return "一加 1";
	}elseif(preg_match('/(HUAWEI P7-L09)/i', strtolower($user_agent))){
		return "华为Ascend P7";
	}elseif(preg_match('/(X900)/i', strtolower($user_agent))){
		return "乐视乐Max";
	}elseif(preg_match('/(vivo X5V)/i', strtolower($user_agent))){
		return "vivo X5V";
	}elseif(preg_match('/(PE-TL10)/i', strtolower($user_agent))){
		return "荣耀6 plus";
	}elseif(preg_match('/(MZ-MX4)/i', strtolower($user_agent))){
		return "魅族MX4";
	}elseif(preg_match('/(Xiaomi_2013022)/i', strtolower($user_agent))){
		return "红米 1";
	}elseif(preg_match('/(MLLED R9)/i', strtolower($user_agent))){
		return "米蓝 R9";
	}elseif(preg_match('/(HUAWEI Y600D-C00)/i', strtolower($user_agent))){
		return "华为Y600D";
	}elseif(preg_match('/(Lenovo A3580)/i', strtolower($user_agent))){
		return "联想黄金斗士A8";
	}elseif(preg_match('/(NX541J)/i', strtolower($user_agent))){
		return "努比亚 NX541J";
	}elseif(preg_match('/(Lenovo-K30-T)/i', strtolower($user_agent))){
		return "联想乐檬K3";
	}elseif(preg_match('/(ATH-TL00H)/i', strtolower($user_agent))){
		return "荣耀7i";
	}elseif(preg_match('/(YL-Coolpad B770)/i', strtolower($user_agent))){
		return "酷派B770S";
	}elseif(preg_match('/(Hisense_E613M_TDLTE)/i', strtolower($user_agent))){
		return "海信E613M";
	}elseif(preg_match('/(GN8001 RV)/i', strtolower($user_agent))){
		return "金立 8001";
	}elseif(preg_match('/(HS-Hisense E76)/i', strtolower($user_agent))){
		return "海信HS-C899";
	} else*/if(true){
		return  "<br/>".$user_agent;
	}
}

function curlPost($url,$data){
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//设置为POST
    curl_setopt($ch, CURLOPT_POST, 1);
//把POST的变量加上
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    $output = curl_exec($ch);
    curl_close($ch);
    return $output;
}

//-------------------------------------------------域名检测
/**
 *域名小助手
 * 检测域名（Url）
 * @param array $domains 要检测的域名（Url）数组
 * @return 成功时返回，其他返回null
 */
function checkDomainInWechat($domains)
{
    $appId = 855043; //AppId
    $key = 'f7c1cee86e757221b78664034b0dfb78'; //密钥

    $timestamp = time();
    // $sign = md5($appId . $domains . $timestamp . $key);

    $sign = md5($appId . implode('', $domains) . $timestamp . $key);

    //按顺序拼接字符串并通过md5加密得到sign

    $json = array(
        'appid' => $appId,
        'timestamp' => $timestamp,
        'sign' => $sign,
        'list' => $domains,
    );

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, 'http://trace.dodourl.com/dc/api/check');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($json)); //直接将encode出来的json字符串Post到接口上
    $data = curl_exec($ch);
    curl_close($ch);

    if ($data == null) {
        return null;
    }
    return json_decode($data);
}

/***
 * @param $urlArr type is array
 * @return array
 */
function CheckDomainInQQ($urlArr)
{
    $data = array();
    $url = "";
    foreach ($urlArr as $url) {
        $url = $url;
        $item['domain'] = $url;
        if (!strstr($url, "http://")) {
            $url = "http://" . $url;
        }
        $item['checkUrl']= "http://www.urlshare.cn/umirror_url_check?url=" . urlencode($url) . "&loginuin=" . mt_rand(510000, 986546754) . "&plateform=mqq";
//        $content = file_get_contents($item['checkUrl']);
        $content = curl($item['checkUrl'])['html'];
        $item['content'] = $content ."<br/>JieHuiLong";
        if (strstr($content, "已停止访问该网页")) {
            $item['status'] = 0;
        } else {
            $item['status'] = 1;
        }
        $data[] = $item;
    }
//    dd($data);
    return $data;
}
function CheckDomainInQQFileGet($urlArr)
{
    $data = array();
    $url = "";
    foreach ($urlArr as $url) {
        $url = $url;
        $item['domain'] = $url;
        if (!strstr($url, "http://")) {
            $url = "http://" . $url;
        }
        $item['checkUrl']= "http://www.urlshare.cn/umirror_url_check?url=" . urlencode($url) . "&loginuin=" . mt_rand(510000, 986546754) . "&plateform=mqq";
        $content = file_get_contents($item['checkUrl']);

//        $content = curl($item['checkUrl'])['html'];
        $item['content'] = $content ."<br/>JieHuiLong";
        if (strstr($content, "已停止访问该网页")) {
            $item['status'] = 0;
        } else {
            $item['status'] = 1;
        }
        $data[] = $item;
    }
//    dd($data);
    return $data;
}




//-------------------------------------------------域名检测

function curlGet($url)
{
    $timeout = 300;
    $ch      = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    $result = curl_exec($ch);
    curl_close($ch);
//    $arr = json_decode($result, true);
    return $result;
}

function sendSMS($to,$datas,$tempId = '153579')
{
    include_once(base_path('vendor/ccp_sms')."/CCPRestSmsSDK.php");

//主帐号,对应开官网发者主账号下的 ACCOUNT SID
    $accountSid= '8a216da8566d116601566e9617d30286';

//主帐号令牌,对应官网开发者主账号下的 AUTH TOKEN
    $accountToken= 'bbb33046c41245a790afc22ce0c90636';

//应用Id，在官网应用列表中点击应用，对应应用详情中的APP ID
//在开发调试的时候，可以使用官网自动为您分配的测试Demo的APP ID
    $appId='8a216da8566d116601566e961837028c';

//请求地址
//沙盒环境（用于应用开发调试）：sandboxapp.cloopen.com
//生产环境（用户应用上线使用）：app.cloopen.com
    $serverIP='app.cloopen.com';


//请求端口，生产环境和沙盒环境一致
    $serverPort='8883';

//REST版本号，在官网文档REST介绍中获得。
    $softVersion='2013-12-26';

    // 初始化REST SDK
    //global $accountSid,$accountToken,$appId,$serverIP,$serverPort,$softVersion;
    $rest = new REST($serverIP,$serverPort,$softVersion);
    $rest->setAccount($accountSid,$accountToken);
    $rest->setAppId($appId);

    // 发送模板短信
    $str = "Sending TemplateSMS to $to <br/>";
    $result = $rest->sendTemplateSMS($to,$datas,$tempId);
    if($result == NULL ) {
        $str .= "result error!";
        return false;
    }
    if($result->statusCode!=0) {
        $str .= "error code :" . $result->statusCode . "<br>";
        $str .= "error msg :" . $result->statusMsg . "<br>";
        //TODO 添加错误处理逻辑
    }else{
        $str .=  "Sendind TemplateSMS success!<br/>";
        // 获取返回信息
        $smsmessage = $result->TemplateSMS;
        $str .=  "dateCreated:".$smsmessage->dateCreated."<br/>";
        $str .=  "smsMessageSid:".$smsmessage->smsMessageSid."<br/>";
        //TODO 添加成功处理逻辑
    }
    return $str;
}



/**
 * $filename  real file path
 * $delete_time cache save time xxx/minute
 * check cache update time
 */
function cache_check($filename, $delete_time = 0)
{
    if (is_file($filename)) {
        if ($delete_time) {
            $t = time();
            $ft = filemtime($filename);
            if ($t - $ft < $delete_time * 3600) {
                return true;
            }
        } else {
            return true;
        }
    }
    return false;
}

/**
 * @param int $begin
 * @param int $end
 * @param int $limit
 * @return array
 */
function getNumberRand($begin = 0, $end = 20, $limit = 5)
{
    $rand_array = range($begin, $end);
    shuffle($rand_array); //调用现成的数组随机排列函数
    return array_slice($rand_array, 0, $limit); //截取前$limit个
}
/**
 * 判断网络文件是否存在
 * @param $fileUrl String file url for target
 * @return bool|mixed  error:return false normal: return true
 */
function isFileExists($fileUrl){
    $fileExists = @file_get_contents($fileUrl,null,null,-1,1) ? true : false ;
    return $fileExists;
}
/**
 * @param $str need to repalce strings
 * @return bool|mixed  error:return false normal: return res after replace,that type is string
 */
function delete_url($str){
    try{
        $str = preg_replace('/(https|http|ftp|rtsp|mms)?:\/\/[0-9a-z\.\/\-]+\/[0-9a-z\.\/\-]+\.([0-9a-z\.\/\-]+)/','',$str);
        return $str;
    }catch (Exception $e){
        return false;
    }
}


/**
 * @param $str need to format for string
 * @return bool|mixed  false: return false , true:return $str,that type is string
 */
function check_messy_code($str){
    $strOjb = preg_replace('/[^\x{4e00}-\x{9fff}]+/u', '', $str);
    if (mb_strlen($strOjb) < 7) {
        return false;
    }
    return $strOjb;
}

/**
 * 时间戳格式化
 * @param int $time
 * @return string 完整的时间显示
 * @author huajie <banhuajie@163.com>
 */
function time_format($time = NULL,$format='Y-m-d H:i:s'){
    $time = $time === NULL ? time() : intval($time);
    return date($format, $time);
}

/**
 * @param $url  website string
 * @return string Domain name
 */
function get_domain($url)
{
    preg_match('/\/\/(.*?)\//', $url, $matches);
    $strArr = explode('.', $matches[1]);
    $domian = array_slice($strArr, -2, 1)[0] . '.' . end($strArr);
    return strtolower($domian);
}

/**
 * Curl collect
 */
function curl($url)
{
    try {
        $data = array();
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);//这个是重点。
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($ch, CURLOPT_HEADER, false);
        curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.103 Safari/537.36');
        curl_setopt($ch, CURLOPT_TIMEOUT, 20);
        curl_setopt($ch, CURLOPT_ENCODING, 'gzip');
        $data['html'] = curl_exec($ch);
        $data['http'] = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        $data['realUrl'] = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
        curl_close($ch);
        //get remote page encode
        $wcharset = preg_match("/<meta(.*?)charset=[^\w]?([-\w]+)/i", $data['html'], $charsetArr);
        $data['charset'] = strtolower(end($charsetArr));
        //convert origin encode
        if (!empty($data['charset'])) {
            try {
                $data['html'] = mb_convert_encoding($data['html'], 'UTF-8', $data['charset']);
                //get Title
                preg_match_all("/<title>(.*)<\/title>/s", $data['html'], $titleArr, PREG_PATTERN_ORDER);
                if (!empty(end($titleArr))) {
                    $data['title'] = end($titleArr)[0];
                }
            } catch (Exception $e) {

            }
        }

        $data['encode'] = strtolower(mb_detect_encoding($data['html']));
    } catch (Exception $e) {
        $data['html'] = "";
    }
    return $data;
}

	//转码
function file_utf8($filepath){
	
	$f_contents= file_get_contents($filepath);
	$encoding = mb_detect_encoding($f_contents, array('GB2312','GBK','UTF-16','UCS-2','UTF-8','BIG5','ASCII'));
	$content_u="";
	$hz = substr($filepath, strrpos($filepath, '.')+1);
	if(strstr($hz,"csv")){
		$filepath = fopen($filepath,'r'); 
		while ($data = fgetcsv($filepath)) { //每次读取CSV里面的一行内容
			if ($encoding != false) {
				$buffer = iconv($encoding, 'UTF-8', $data[0]);
			}else{
				$buffer = mb_convert_encoding ( $data[0], 'UTF-8','Unicode');
			}
			$content_u.= $buffer.'!@#!@#';
		}
		 fclose($filepath);
	}elseif(strstr($hz,"txt")){
		$handle=fopen($filepath,"r");
		if ($handle){
			while (!feof($handle)) {
				$buffer= fgets($handle);
				if ($encoding != false) {
					$buffer = iconv($encoding, 'UTF-8', $buffer);
				}else{
					$buffer = mb_convert_encoding ( $buffer, 'UTF-8','Unicode');
				}
				$content_u.=$buffer.'!@#!@#';
			} 
		}
		fclose($handle);
	}
	return $content_u;
}
//根据uid获取角色名称
function getRoleName($uid){
    if($uid == 1){
        $name = "超级管理员";
    }else{
        $ru = RoleUser::where('user_id',$uid)->first();
		if(!$ru) return "未分配角色";
        $name =  Role::where('id',$ru->role_id)->value('name');
        $name = $name ? $name : "未分配角色";
    }
    return $name;
}
//根据uid获取所有下级id
function getCids($uid){
	$userids[]['id']=$uid;
	$pids[]=$uid;
	do{
		$pids = User::select('id')->whereIn('pid',$pids)->get()->toArray();
		if(count($pids)>0)$userids = array_merge($userids,$pids);
	}while(count($pids)>0);
	return $userids;
}
//根据微信id，获取分组所属用户名称
/* function getWechatUserName($wid){
	$wechat = Wechat::find($wid);
	$wechat_group = WechatGroup::find($wechat->group);
	return User::where('id',$wechat_group->uid)->value('name');
} */
//根据uid获取所属推广用户的id
function getTid($uid){
	$user = User::find($uid);
	$role_user = RoleUser::where('user_id',$uid)->value('role_id');
	if($role_user==6) return $user->id;
	while($user->pid!=0&&$role_user!=6){
		$user = User::find($user->pid);
		$role_user = RoleUser::where('user_id',$user->id)->value('role_id');
		if($role_user==6) return $user->id;
	}
	//return $role_user;
}
function httpcode($url){
  $ch = curl_init();
  $timeout = 3;
  curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
  curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  curl_setopt($ch, CURLOPT_HEADER, 1);
  curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
  curl_setopt($ch,CURLOPT_URL,$url);
  curl_exec($ch);
  $httpcode = curl_getinfo($ch,CURLINFO_HTTP_CODE);
  curl_close($ch);
  return $httpcode;
}